﻿using System;
using System.Text.RegularExpressions;
using NUnit.Framework;
using YGD.MicroBlogAnalysis;

namespace UnitTest
{
    [TestFixture]
    public class unittest_MicroBlogAnalysis
    {
        [Test]
        public void AnalysisTask_test_simple_task()
        {
            var analysis = new MicroBlogAnalysis();
            TaskBase taskBase = analysis.AnalysisTask("Have lunch@superwolf@runaway");

            Assert.AreEqual("Have lunch", taskBase.Content);
            Assert.AreEqual(2, taskBase.UserNames.Count);

        }

        [Test]
        public void AnalysisTask_test_with_timingString_task()
        {
            var analysis = new MicroBlogAnalysis();
            string blogString = "Have lunch@superwolf@runaway 今天下午五点";
            TaskBase taskBase = analysis.AnalysisTask(blogString);

            Assert.AreEqual("Have lunch", taskBase.Content);
            Assert.AreEqual(2, taskBase.UserNames.Count);
            Assert.AreEqual("今天下午五点", taskBase.TimingString);

            var expectedDatetime = DateTime.Today.AddHours(17);
            Assert.AreEqual(expectedDatetime, taskBase.Timing);

        }

        //今天17:00
        [Test]
        public void AnalysisTask_test_with_timing_task1()
        {
            var analysis = new MicroBlogAnalysis();
            string blogString = "Have lunch@superwolf@runaway 今天17:00";
            TaskBase taskBase = analysis.AnalysisTask(blogString);

            Assert.AreEqual("Have lunch", taskBase.Content);
            Assert.AreEqual(2, taskBase.UserNames.Count);

            var expectedDateTime = DateTime.Today.AddHours(17);
            Assert.AreEqual(expectedDateTime.ToString(), taskBase.Timing.ToString());
        }

        //7:00
        [Test]
        public void AnalysisTask_test_with_timing_task2()
        {
            var analysis = new MicroBlogAnalysis();
            string blogString = "Have lunch@superwolf@runaway 7:00";
            TaskBase taskBase = analysis.AnalysisTask(blogString);

            Assert.AreEqual("Have lunch", taskBase.Content);
            Assert.AreEqual(2, taskBase.UserNames.Count);

            var expectedDateTime = DateTime.Today.AddHours(7);
            Assert.AreEqual(expectedDateTime.ToString(), taskBase.Timing.ToString());
        }

        //10-10 7:00
        [Test]
        public void AnalysisTask_test_with_timing_task3()
        {
            var analysis = new MicroBlogAnalysis();
            string blogString = "Have lunch@superwolf@runaway 10-10 7:00";
            TaskBase taskBase = analysis.AnalysisTask(blogString);

            var expectedDateTime = Convert.ToDateTime("10-10").AddHours(7);
            Assert.AreEqual(expectedDateTime.ToString(), taskBase.Timing.ToString());
        }

        //10-10 7点
        [Test]
        public void AnalysisTask_test_with_timing_task4()
        {
            var analysis = new MicroBlogAnalysis();
            string blogString = "Have lunch@superwolf@runaway 10-10 7点";
            TaskBase taskBase = analysis.AnalysisTask(blogString);

            var expectedDateTime = Convert.ToDateTime("10-10").AddHours(7);
            Assert.AreEqual(expectedDateTime.ToString(), taskBase.Timing.ToString());
        }

        //3点
        [Test]
        public void AnalysisTask_test_with_timing_task5()
        {
            var analysis = new MicroBlogAnalysis();
            string blogString = "Have lunch@superwolf@runaway 3点";
            TaskBase taskBase = analysis.AnalysisTask(blogString);

            var expectedDateTime = DateTime.Today.AddHours(3);
            Assert.AreEqual(expectedDateTime.ToString(), taskBase.Timing.ToString());
        }

        [Test]
        public void TestDatetimeConvert()
        {
            string dateString = "1-2";
            var date = Convert.ToDateTime(dateString);
            date.AddHours(10);

            var re = new Regex(@"(\d{2,4}[-./]\d{1,2}[-./]\d{1,2})|(\d{1,2}[-./]\d{1,2})");
            var mc = re.Match("1-2 10:12");

            Assert.AreEqual(dateString,mc.Value);
            


        }
    }
}
